package com.zfjt.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.zfjt.constants.InterfaceDefinition;
import com.zfjt.entity.ClientmessageBean;
import com.zfjt.entity.OrderBean;
import com.zfjt.entity.ReturnBean;
import com.zfjt.packnum.PackNum00025;
import com.zfjt.service.ClientmessageBeanService;

/**
 * 删除订单
 * @author xk
 * @version 1.0
 * @date 2017年4月07日
 */
@Controller
public class RemoveOrderController {
	
	private ReturnBean mReturn;
	
	@Autowired
	private ClientmessageBeanService mClientMessage;
	
	private Map<String, String> fhdata; 
	
	private List<ClientmessageBean> mAllData;
	
	private List<OrderBean> mData;
	
	@RequestMapping(value="00025")
	@ResponseBody
	public ReturnBean RemoveOrder(HttpSession hseesion){
		mAllData = new ArrayList<>();
		mData = new ArrayList<>();
		mReturn = new ReturnBean();
		fhdata = new HashMap<>();
		//传过来的参数
		String data =  (String) hseesion.getAttribute("data");
		PackNum00025 num00025 = JSON.parseObject(data,PackNum00025.class); 	
		List<ClientmessageBean> mList = mClientMessage.selectAll();
		if (data.equals(InterfaceDefinition.IStatusCode.TOKEN_FAILURE)) {//校验码错误
			mReturn.setCode("001");
			mReturn.setPortnum("00025");
			fhdata.put("error", "TOKEN_ERROR");
			mReturn.setData(JSON.toJSONString(fhdata));
		}else{	
			if (num00025.getType().equals("1")) {//删除所有未完成的订单
				for (int i = 0; i < mList.size(); i++) {
					ClientmessageBean dg = mList.get(i);
					if (dg.getReject().equals("0")) {
						mClientMessage.deleteByPrimaryKey(dg.getId());
					}
				}
			}else if (num00025.getType().equals("2")) {
				mClientMessage.deleteByPrimaryKey(Short.parseShort(num00025.getId()));
			}
			mReturn.setCode("000");
			mReturn.setData("chenggong");
			mReturn.setPortnum("00025");
		}
		return mReturn;
	}
}
